package connectionpool.internal;


import java.util.Properties;

import connectionpool.ConnectionPool;



/*****************************************************************************
 * @author amahmood
 * 
 *         Connection pool builder.
 *         Creates a Connection Manger and passes it to connection pool.
 ****************************************************************************/
public class ConnectionPoolFactory
{

    /*****************************************************************************
     * @param poolSize
     * @param dbProperties
     * @return
     ****************************************************************************/
    private static ConnectionPool createConnectionPool(int poolSize, Properties dbProperties)
    {
        ConnectionManager connectionManger = new ConnectionManager(dbProperties);

        ConnectionPoolImpl connectionPool = new ConnectionPoolImpl(poolSize, connectionManger);

        String debugValue = dbProperties.getProperty(DbPropertyNames.DEBUG.name(), Boolean.FALSE.toString());
        connectionPool.setDebug(Boolean.valueOf(debugValue));

        return connectionPool;
    }

    /**
     * *************************************************************************
     * 
     * 
     * @param poolSize
     * @param dbProperties
     * @return
     * ****************************************************************************/
    public static ConnectionPool getConnectionPool(int poolSize, Properties dbProperties)
    {
        ConnectionPool connectionPool;

        connectionPool = createConnectionPool(poolSize, dbProperties);

        return connectionPool;
    }

    /*****************************************************************************
     * @return
     ****************************************************************************/
    public static ConnectionPool getDefaultConnectionPool()
    {
        ConnectionPool connectionPool;

        connectionPool = createConnectionPool(5, DbProperties.getDefaultProperties());
        return connectionPool;
    }
}
